﻿/*
 * Created by SharpDevelop.
 * User: ivo.stoykov
 * Date: 5.12.2013 г.
 * Time: 13:04
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Dynamic;
using System.Linq;
using System.Windows.Forms;

namespace DictNS
{
  /// <summary>
  /// Description of EntryList.
  /// </summary>
  public partial class EntryList : Form
  {
    
    public Dictionary<String, String> WordList {  get; set; }
    public KeyValuePair<String, String> ChosenWord;
    public EntryList()
    {
      //
      // The InitializeComponent() call is required for Windows Forms designer support.
      //
      InitializeComponent();
      WordList = new Dictionary<string, string>();
      ChosenWord = new KeyValuePair<String, String>();
    }
    
    void EntryListLoad(object sender, EventArgs e)
    {
      if(WordList == null) { return; }
      lbDefinitions.DataSource = (from val in WordList.Values select val).ToList();
//      lbDefinitions.ClearSelected();
    }
    
    void LbDefinitionsSelectedIndexChanged(object sender, EventArgs e)
    {
      ListBox lb = (sender as ListBox);
      ChosenWord = WordList.Where(rec => rec.Value == lb.Text).ToDictionary(k => k.Key, v => v.Value).FirstOrDefault();
    }
    
    void LbDefinitionsMouseDoubleClick(object sender, MouseEventArgs e)
    {
      ListBox lb = (sender as ListBox);
      if(lb.SelectedItem == null) {  return;  }
      btnOK.PerformClick();
    }
    
    void LbDefinitionsKeyPress(object sender, KeyPressEventArgs e)
    {
      switch (e.KeyChar) {
        case (char)Keys.Enter:
          e.Handled = true;
          btnOK.PerformClick();
          break;
        case (char)Keys.Escape:
          e.Handled = true;
          btnCancel.PerformClick();
          break;
      }
    }
  }
}
